package com.spring.IoCStudy_02;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

// 作用域配置注解
//@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON) // 单例
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE) // 多例

// 普通组件声明注解
@Component  // id名取默认值，为类名但首字母小写的形式。相当于<bean id="commonComponent" class="CommonComponent" />
// @Component(value = "cc")    // value指定id名字
// @Component("cc")    // 相当于value = "cc"，简化写法

public class CommonComponent {

    // 周期方法（init和destroy)的注解声明：分别是@PostConstruct（实例化组件之后）和@PreDestroy（销毁对象之前）

    @PostConstruct
    public void init() {
        System.out.println("CommonComponent init");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("CommonComponent destroy");
    }
}
